package com.iweb;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

//servlet 3.0写法  不需要配置了 只要写注解就可以了
@WebServlet(name = "SecondServlet",urlPatterns = "/sec")
public class SecondServlet extends HttpServlet {
    //get请求用doGet处理
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("调用了doGet请求");
        //设置一下返回处理的结果集的字符集
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("utf-8");
        resp.setContentType("text/html; charset=UTF-8");
        resp.getWriter().write("返回相应的数据");
    }

    //Post请求用doPost处理
//
//    @Override
//    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        super.doPost(req, resp);
//    }
}
